-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow *const W<dyn A> -> *const dyn A
ptr cast
#136127
Conversation
Implementation wise I feel like I'm not using the trait solver APIs correctly and all this feels quite hack-y. I'd be glad to hear suggestions on how to improve it. |
For the language team nomination: I feel like this is an easy decision. We already support the opposite cast impl<T: ?Sized> Wrapper<T> {
fn get(this: *const Self) -> *const T {
this as _
}
}
fn cast(ptr: *const Wrapper<dyn Super>) -> *const dyn Super {
Wrapper::get(ptr)
} So I'd argue that the reason we don't support |
This comment has been minimized.
This comment has been minimized.
.structurally_normalize(ty, &mut *fulfill_cx) | ||
}; | ||
|
||
// N.B. use `target`, not `coerce_target` (the latter is a var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify in a comment what this is doign? also, i think the "kind match + normalize projection + check its adt kind" can be uplifted into a closure, not just the normalize part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
er, actually maybe just move that comment from above down here?
This comment was marked as resolved.
This comment was marked as resolved.
5183b33
to
804a940
Compare
@rustbot ready |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
cc @rust-lang/types |
pls ping me @WaffleLapkin when this is over, I'll give it one more careful review once the fcp is done. |
To confirm, @WaffleLapkin, the intent of this PR is to say "you can cast between two wide raw pointers so long as the metadata is the same vtable in both", roughly speaking? I take it that the logic is consistency -- i.e., we allow you to convert |
This comment was marked as resolved.
This comment was marked as resolved.
☔ The latest upstream changes (presumably #138058) made this pull request unmergeable. Please resolve the merge conflicts. |
e620d98
to
3b28c69
Compare
the errors should not be there, this is a bug/missing feature.
this prevents us from trying unsizing coercion in cases like `*const W<dyn T>` -> `*const dyn T`, where it would later cause a compilation error since `W<dyn T>: Sized` and `W<dyn T>: T` do not hold.
yay, I fixed the bug/missing feature :')
3b28c69
to
80157a5
Compare
@bors r+ rollup |
er, @bors rollup=maybe |
…r=compiler-errors Allow `*const W<dyn A> -> *const dyn A` ptr cast Followup of rust-lang#120248 (comment). This PR allows casting pointers from something wrapping a trait object, to the trait object, i.e. `*const W<dyn A> -> *const dyn A` where `W` is `struct W<T: ?Sized>(T);`. r? compiler-errors Fixes rust-lang#128625
Rollup of 16 pull requests Successful merges: - rust-lang#122790 (Apply dllimport in ThinLTO) - rust-lang#136127 (Allow `*const W<dyn A> -> *const dyn A` ptr cast) - rust-lang#136968 (Turn order dependent trait objects future incompat warning into a hard error) - rust-lang#137147 (Add exclude to config.toml) - rust-lang#137319 (Stabilize `const_vec_string_slice`) - rust-lang#137885 (tidy: add triagebot checks) - rust-lang#138040 (compiler: Use `size_of` from the prelude instead of imported) - rust-lang#138052 (strip `-Wlinker-messages` wrappers from `rust-lld` rmake test) - rust-lang#138084 (Use workspace lints for crates in `compiler/`) - rust-lang#138158 (Move more layouting logic to `rustc_abi`) - rust-lang#138160 (depend more on attr_data_structures and move find_attr! there) - rust-lang#138192 (crashes: couple more tests) - rust-lang#138216 (bootstrap: Fix stack printing when a step cycle is detected) - rust-lang#138232 (Reduce verbosity of GCC build log) - rust-lang#138233 (Windows: Don't link std (and run-make) against advapi32, except on win7) - rust-lang#138242 (Revert "Don't test new error messages with the stage 0 compiler") r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#136127 (Allow `*const W<dyn A> -> *const dyn A` ptr cast) - rust-lang#136968 (Turn order dependent trait objects future incompat warning into a hard error) - rust-lang#137319 (Stabilize `const_vec_string_slice`) - rust-lang#137885 (tidy: add triagebot checks) - rust-lang#138040 (compiler: Use `size_of` from the prelude instead of imported) - rust-lang#138084 (Use workspace lints for crates in `compiler/`) - rust-lang#138158 (Move more layouting logic to `rustc_abi`) - rust-lang#138160 (depend more on attr_data_structures and move find_attr! there) - rust-lang#138192 (crashes: couple more tests) - rust-lang#138216 (bootstrap: Fix stack printing when a step cycle is detected) - rust-lang#138232 (Reduce verbosity of GCC build log) - rust-lang#138242 (Revert "Don't test new error messages with the stage 0 compiler") r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#136127 - WaffleLapkin:dyn_ptr_unwrap_cast, r=compiler-errors Allow `*const W<dyn A> -> *const dyn A` ptr cast Followup of rust-lang#120248 (comment). This PR allows casting pointers from something wrapping a trait object, to the trait object, i.e. `*const W<dyn A> -> *const dyn A` where `W` is `struct W<T: ?Sized>(T);`. r? compiler-errors Fixes rust-lang#128625
@rust-timer build 63be0e2 |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (63be0e2): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 1.4%, secondary 2.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 1.5%, secondary 4.8%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 765.417s -> 767.302s (0.25%) |
This PR seems to have caused a rather large perf. regression. Do you think it could be avoided somehow? This feature doesn't sound that complex that it would have to cause such perf. hits. Thanks! |
Can u open an issue @Kobzol to track it? I am on my phone but I can take a look at how to fix this perf regression later or maybe brainstorm w Waffle. edit: nvm i just cross-linked the pr. probably no tracking issue needed. |
…r=<try> Use struct tail rather than metadata projection to compute coercion fast path cc rust-lang#136127 (comment) r? `@ghost`
…r=<try> Use struct tail rather than metadata projection to compute coercion fast path cc rust-lang#136127 (comment) r? `@ghost`
Followup of #120248 (comment).
This PR allows casting pointers from something wrapping a trait object, to the trait object, i.e.
*const W<dyn A> -> *const dyn A
whereW
isstruct W<T: ?Sized>(T);
.r? compiler-errors
Fixes #128625